package com.jas.common;
//@author A0098803W
import java.util.Calendar;

//@author A0098803W
/**
 * This class is holds the details of an event set for notification.
 * 
 */
public class Notification {
	private String notificationId;
	private Calendar timeToNotify;

	private String message;

	private boolean executionStatus;

	public Notification() {
		this(Utilities.generateUniqueIdentification());
	}

	public Notification(String notificationId) {
		this.notificationId = notificationId;
		this.executionStatus = false;
	}

	//@author A0098803W
	/**
	 * Gets the event id for this <code>Notification</code> object.
	 * 
	 * @return The event's unique id.
	 */
	public String getNotificationId() {
		return notificationId;
	}

	//@author A0098803W
	/**
	 * Sets the event id for this <code>Notification</code> object.
	 * 
	 * @param notificationId
	 *            The event id to use.
	 */
	public void setNotificationId(String notificationId) {
		this.notificationId = notificationId;
	}

	//@author A0098803W
	/**
	 * Gets the <code>Calendar</code> object for this <code>Notification</code>
	 * object. This <code>Calendar</code> holds the time to execute the
	 * notification.
	 * 
	 * @return Returns the <code>Calendar</code> object sets for the current
	 *         event ID.
	 */
	public Calendar getTimeToNotify() {
		return timeToNotify;
	}

	//@author A0098803W
	/**
	 * Sets the <code>Calendar</code> object for this <code>Notification</code>
	 * object. This function sets the notification time.
	 * 
	 * @param timeToNotify
	 *            The time to notify.
	 * @throws DateFormatException 
	 * @throws CommandFormatException 
	 */
	public void setTimeToNotify(Calendar timeToNotify) throws DateFormatException  {
		Calendar cal = Calendar.getInstance();
		int currentDay = cal.get(Calendar.DAY_OF_MONTH);
		int currentMonth = cal.get(Calendar.MONTH);
		int currentYear = cal.get(Calendar.YEAR);
		int currentHour = cal.get(Calendar.HOUR);
		int currentMinute = cal.get(Calendar.MINUTE);

		int userCurrentDay = timeToNotify.get(Calendar.DAY_OF_MONTH);
		int userCurrentMonth = timeToNotify.get(Calendar.MONTH);
		int userCurrentYear = timeToNotify.get(Calendar.YEAR);
		int userCurrentHour = timeToNotify.get(Calendar.HOUR);
		int userCurrentMinute = timeToNotify.get(Calendar.MINUTE);
		// Calendar.getInstance() returns a different time format
		// from this program time format
		// Hence, this workaround is used instead
		if (cal.before(timeToNotify)) {
			this.timeToNotify = timeToNotify;
		}
		else{
			
				throw new DateFormatException(Language.getString("ERROR_INVALID_DATE_INPUT"));
			
		}

	}

	//@author A0098803W
	/**
	 * Gets the message to use for notification.
	 * 
	 * @return Returns the notification message.
	 */
	public String getMessage() {
		return message;
	}

	//@author A0098803W
	/**
	 * Sets the message to use for notification.
	 * 
	 * @param message
	 *            Sets the notification message.
	 * @throws CommandFormatException 
	 */
	public void setMessage(String message) throws CommandFormatException {
		message.trim();
		if(message.isEmpty()){
			throw new CommandFormatException(Language.getString("ERROR_WRONG_COMMAND_FORMAT"));
		}
		this.message = message;
	}

	//@author A0098803W
	/**
	 * Gets the status whether the notification has been executed or otherwise.
	 * 
	 * @return Returns <code>true</code> if notification is successful,
	 *         <code>false</code> if unsuccessful.
	 */
	public boolean isExecutionStatus() {
		return executionStatus;
	}

	//@author A0098803W
	/**
	 * Sets the status whether the notification has been executed or otherwise.
	 * 
	 * @param executionStatus
	 *            Sets to <code>true</code> if notification is executed,
	 *            <code>false</code> if otherwise.
	 */
	public void setExecutionStatus(boolean executionStatus) {
		this.executionStatus = executionStatus;
	}

}
